<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <!-- 用户id、ip、登录时间、地区、状态 -->
            <a-col :md="8" :sm="24">
              <a-form-item label="产品">
                <a-select v-model="queryParam.productId" placeholder="" >
                  <a-select-option value="jack" v-for="it in productList" :key="it.id">
                    {{it.name}}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            
            <a-col :md="8" :sm="24">
              <a-form-item label="登录时间">
                <a-range-picker
                  show-time
                  v-model="queryParam.buildTime"
                  valueFormat="YYYY-MM-DD HH:mm:ss"
                  style="width: 100%"
                  :placeholder="['请选择开始日期', '请选择结束日期']"
                />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <span
                class="table-page-search-submitButtons"
                :style="(advanced && { float: 'right', overflow: 'hidden' }) || {}"
              >
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (this.queryParam = {})">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        showPagination="auto"
        :scroll="{ x: 'auto' }"
      >
        <span slot="status" slot-scope="text">
          <a-badge :color="text | statusFilter(statusList, 'status')" :text="text | statusFilter(statusList, 'name')" />
        </span>
        <span slot="param" slot-scope="text">
          <div class="remark-wrap">{{ text }}</div>
        </span>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import moment from 'moment'
import { STable, Ellipsis } from '@/components'
import { smsBalanceLogList } from '@/api/finance'
import { productByNoAuth } from '@/api/noAuth'

import { statusList, eachMap } from '@/utils/other'

const columns = [
  {
    title: '用户名称',
    dataIndex: 'userName',
    width: '180px',
  },
  {
    title: '充值类型',
    dataIndex: 'rechargeType',
    width: '180px',
  },
  {
    title: '充值订单',
    dataIndex: 'orderId',
    width: '180px',
  },
  {
    title: '金额',
    dataIndex: 'money',
    width: '180px',
  },
  {
    title: '添加人员',
    dataIndex: 'addByName',
    width: '180px',
  },
   {
    title: '添加时间',
    dataIndex: 'addTime',
    width: '180px',
  },
  
  {
    title: '状态',
    dataIndex: 'status',
    width: '100px',
    scopedSlots: { customRender: 'status' },
  },
]

export default {
  name: 'userLoginList',
  components: {
    STable,
    Ellipsis,
  },
  data() {
    this.columns = columns
    return {
      // create model
      visible: false,
      confirmLoading: false,
      mdl: null,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      parameter: {
        pageNum: 1,
        pageSize: 10,
      },
      queryParam: {},
      data: [],
      // 状态
      statusList,
      // typeList,
      // 排序
      sortJ: {
        addTime: 'log.add_time',
      },
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        let sortJ = this.sortJ
        if (parameter.sortField) {
          parameter.sortJ = sortJ
        }
        const requestParameters = Object.assign({ direction: 2 }, parameter, this.queryParam)
        if(requestParameters.buildTime){
          requestParameters.endTime = requestParameters.buildTime[1] || ''
          requestParameters.startTime = requestParameters.buildTime[0] || ''
          delete requestParameters.buildTime
        }
         
        return smsBalanceLogList(requestParameters).then((res) => {
          let result = {
            data: res.data.data,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalCount: res.data.total,
            totalPage: res.data.pages,
          }
          return result
        })
      },
      productList: [],
      selectedRowKeys: [],
      selectedRows: [],
    }
  },
  created() {},
  computed: {},
  methods: {
    getList(){
      productByNoAuth({pageSize: 100, pageNum: 1})
      .then(res=>{
        this.productList = res.data.data
      })
    },
    handleAdd() {
      this.mdl = null
      this.visible = true
    },
    handleEdit(record) {
      this.visible = true
      this.mdl = { ...record }
    },
  },
}
</script>

 